package mas;

import java.util.ArrayList;

import rinde.sim.core.graph.*;
public class Zone {
	
	private Point bottomLeft, topRight;
	//a point as close to the center as possible (since it is not possible to just take the center when there is no node there)
	private Point referencePoint;
	private int zoneNumber;
	private ArrayList<Box> boxes;

	public Zone(Point bottomLeft, Point topRight, int zoneNumber){
		this.bottomLeft=bottomLeft;
		this.topRight=topRight;
		this.zoneNumber=zoneNumber;
		this.boxes = new ArrayList<Box>();
	}
	
	public void addBox(Box box){
		boxes.add(box);
	}
	
	public ArrayList<Box> getBoxes(){
		return boxes;
	}
	
	//for placing the agents in the beginning
	public Point getCenter(){
		double centerX = (this.getBottomLeft().x + this.getTopRight().x)/2;
		double centerY = (this.getBottomLeft().y + this.getTopRight().y)/2;
		Point center = new Point(centerX, centerY);
		return center;
	}
	
	public Point getBottomLeft() {
		return bottomLeft;
	}
	public void setBottomLeft(Point bottomLeft) {
		this.bottomLeft = bottomLeft;
	}
	public Point getTopRight() {
		return topRight;
	}
	public void setTopRight(Point topRight) {
		this.topRight = topRight;
	}
	public Point getReferencePoint() {
		return referencePoint;
	}
	public void setReferencePoint(Point referencePointt) {
		this.referencePoint = referencePointt;
	}
	public int getZoneNumber() {
		return zoneNumber;
	}
	public void setZoneNumber(int zoneNumber) {
		this.zoneNumber = zoneNumber;
	}
	public boolean containsPoint(Point point){
		return (point.x >= bottomLeft.x && point.y >= bottomLeft.y && point.x <= topRight.x && point.y <= topRight.y);
	}
	
	public double getRelativeDistanceFromCenter(Point otherPoint){
		double xDiff = otherPoint.x - this.getCenter().x;
		double yDiff = otherPoint.y - this.getCenter().y;
		double distance = Math.sqrt(xDiff*xDiff+yDiff*yDiff);
		double squareWidth = this.getTopRight().x - this.getBottomLeft().x;
		return distance/squareWidth;
	}
}
